<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/base_user.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>支付方式</title>
    <script src="__STATIC__/password/passwordBox.min.js"></script>
    <script src="__STATIC__/password/md5.js"></script>
    <script>
        $(function () {
            if (!sessionStorage.getItem('auction_order_id')){
                window.location.href = "{:url('mobile/user_info/member_order')}?status={:input('status','all')}&title={:input('title')}";
            }

            if ('{$total}' === '0.00'){
                $('#ba').html('<p style="margin: 2% 0 2% 0 ;padding: 2% 0 2% 0; border-bottom: 3px solid #F7F7F7;">' +
                    '<img src="__STATIC__/img_user/warning29.png" style="width: 40px;height: 40px;" />' +
                    '<span style="text-align:center; display:block;">交易不存在</span>' +
                    '</p>');
                //延时跳转
                setTimeout(function () {
                    window.location.href = "{:url('mobile/user_info/my_shop_index')}"
                },3000);
            }else{
                $('#this_pay_money').text('{$total}');
            }

        })
    </script>
</head>
<body>
<div class="wrap-pay">
    <div class="header">
        <p>请选择支付方式</p>
        <!--未操作返回到未支付订单页面-->
        <img src="__STATIC__/img/back.png" class="back" onclick="back_url()">
    </div>
    <div id="ba" style="text-align:center;width: 100%;height: auto;background-color: #FFFFFF;top: 0;z-index: 9999;">
        <p style="margin: 2% 0 2% 0 ;padding: 2% 0 2% 0; border-bottom: 3px solid #F7F7F7;">本次交易金额</p>
        <p style="color: red;font-size: 24px;padding-bottom:2%;margin: 2.5% 5%" >&yen;<font id="this_pay_money">0.00</font></p>
    </div>
    <div class="center">
        <ul>
            <!--<li>-->
                <!--<label for="radio-1-1"><img src="__STATIC__/img_user/zf-qianbao.png"><span> 钱包余额</span></label>-->
                <!--<input type="radio" id="radio-1-1" name="radio-1-set" class="radio" value="0" checked />-->
            <!--</li>-->
            {eq name="is_weixin" value="2"}
            <li>
                <label for="radio-1-2"><img src="__STATIC__/img_user/zf-hifubao.png"><span> 支付宝</span></label>
                <input type="radio" id="radio-1-2" name="radio-1-set" class="radio" value="1" />
            </li>
            {/eq}
            {eq name="is_weixin" value="1"}
            <li>
                <label for="radio-1-3"><img src="__STATIC__/img_user/zf-weixin.png"><span> 微信</span></label>
                <input type="radio" id="radio-1-3" name="radio-1-set" class="radio" value="2" />
            </li>
            {/eq}
        </ul>

    </div>
    <div class="delete">
        <input type="button" onclick="choose_type()" value="确 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 定">
    </div>
    <div id="alipay" hidden></div>
</div>
{include file="public/src" /}
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    $(function () {
        sessionStorage.removeItem('pay_url');
    });
    function choose_type(){
        if (!sessionStorage.getItem('auction_order_id')){
            layer.open({content:'交易不存在',skin:'msg',time:2});
            //延时跳转
            setTimeout(function () {
                window.location.href = "{:url('mobile/user_info/my_shop_index')}"
            },3000);
            return false;
        }
        if ('{$total}' === '0.00'){
            //延时跳转
            setTimeout(function () {
                window.location.href = "{:url('mobile/user_info/my_shop_index')}"
            },3000);
            return ;
        }
        //用户选择的支付类型
        var type = $("[type='radio']:checked").val();
        if (type == 0){  //余额支付
            dialog_pay();
        }else if (type == 1){ //支付宝支付
            $.ajax({
                url : "{:url('mobile/Alipay/auction')}",
                type:'post',
                dataType:'html',
                data:{'oid':sessionStorage.getItem('auction_order_id'),'body' : '{$information}'},
                success:function (data) {
                    $('#alipay').html(data);
                },
                error: function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            })
        }else if (type == 2){   //微信支付
            callpay();
        }
    }
    function dialog_pay(){
        /**
         * init传入参数依次是：正确密码(传空时不对比输入是否正确),密码键盘背景，标题，副标题
         * */
        var msg = '<a href="javascript:pwd(1);">您还未设置密码,点击去设置</a>';
        if ('{$pass}'){
            msg = "<a href='javascript:pwd(2);' style='float: left;margin-left:10% ;'>修改密码</a>" +
                "<a href='javascript:pwd(3);' style='float: right;margin-right:10% ;'>忘记密码</a>";
        }

        PwdBox.init('{$pass}', "/password/pwd_keyboard.png", '请输入支付密码', '');
        $('.notice').html(msg);
        if (!'{$pass}'){  //若没有设置密码,则移除按键
            $('.input-box').remove();
        }
        /**
         *res格式：{status:'true或false',password:'用户输入的密码'}
         *
         */
        PwdBox.show(function (res) {
            $.post("{:url('mobile/user_category/balance')}",{'p':res.password,'oid':sessionStorage.getItem('auction_order_id')},function (data) {
                if (data.code == 200){
                    sessionStorage.removeItem('auction_order_id');
                    layer.open({content:data.message,skin:'msg'});
                    setTimeout(function () {
                        //跳转到我的全部订单
//                        window.location.href = "{:url('mobile/user_info/member_order')}?status=all";
                    },2000);

                } else if (data.code == 402) {  //余额不足,跳转到充值页面
                    layer.open({content:data.message,skin:'msg',time:2});
                    sessionStorage.setItem('recharge_back_url',window.location.href);
                    setTimeout(function () {
                        window.location.href = "{:url('mobile/recharge/index')}"
                    })
                } else {
                    layer.open({content:data.message,skin:'msg',time:2});
                }
            })
        });
    }
    //跳转支付密码操作页面
    function pwd(type){
        var url = window.location.href;
        var index = url.indexOf('&code=');
        url = url.substring(0,index);
        sessionStorage.setItem('pay_url',url);  //设置返回路径
        switch (type){
            case 1: //设置密码
                if ('{$info.wechat_id}' && !'{$info.username}'){  //微信登录并且未绑定手机号直接跳过手机验证
                    window.location.href = "{:url('mobile/pay_pass/check')}?act=set&paying";
                }else{   //(手机登录)去验证手机号
                    window.location.href = "{:url('mobile/pay_pass/edit')}?act=set&paying";
                }
                break;
            case 2: //修改密码
                window.location.href = "{:url('mobile/pay_pass/check')}?act=edit&paying";
                break;
            case 3: //忘记密码
                if ('{$info.wechat_id}' && !'{$info.username}') {  //微信登录并且未绑定手机号直接跳过手机验证
                    window.location.href = "{:url('mobile/pay_pass/check')}?act=forget&paying";
                }else{  //(手机登录)去验证手机号
                    window.location.href = "{:url('mobile/pay_pass/edit')}?act=forget&paying";
                }
                break;
        }
    }
    //返回
    function back_url(){
        sessionStorage.removeItem('auction_order_id');
        var url = sessionStorage.getItem('auction_pay');
        window.location.href=url;
    }


    function callpay() {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',JSON.parse('{$param}'),
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                    // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                    window.location.href = "{:url('mobile/user_info/member_order')}?status={:input('status','all')}&title={:input('title','')}"
                }
            }
        );
    }

</script>
</body>
</html>